package com.linkage.jz.bankruptcy.adapter.Vote;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.linkage.jz.bankruptcy.R;
import com.linkage.jz.bankruptcy.bean.Vote.ProVoteVotersDetail;
import com.linkage.seapeak.utils.CommonUtils;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;
import jp.wasabeef.glide.transformations.CropCircleTransformation;

/**
 * 表决人员明细--不带分组的adapter
 */
public class ProVoteVotersDetailNoGroupsAdapter extends RecyclerView.Adapter {

    private Context context;
    private List<ProVoteVotersDetail> mData;
    private int pageType;//1已表决页面 2已参会未表决 3未参会

    public ProVoteVotersDetailNoGroupsAdapter(Context context, int pageType, List<ProVoteVotersDetail> mData) {
        this.context = context;
        this.mData = mData;
        this.pageType = pageType;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.adapter_pro_vote_voters_detail_no_group, parent, false);
        /*RecyclerView.ViewHolder holder = null;
        switch (viewType) {
            case HEADER:
                if(headerView != null)
                    holder = new ViewHolderNormal(headerView);
                break;
            case NORMAL:
                view = LayoutInflater.from(context).inflate(R.layout.adapter_find_expert_item, parent, false);
                holder = new ViewHolderNormal(view);
                break;
        }*/
        RecyclerView.ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
        ProVoteVotersDetail item = mData.get(position);
        ViewHolder holder = (ViewHolder)viewHolder;
       /* Glide.with(context).load(holder.avatar)
                .placeholder(R.drawable.avatar_defult)//图片加载出来前，显示的图片
                .error(R.drawable.avatar_defult)//图片加载失败后，显示的图片
                .centerCrop().into(holder.avatar);*/
//       holder.avatar.setImageResource(R.drawable.avatar_defult);
        ImageView imageview = holder.avatar;

        Glide.with(context).load(item.getAvatar())
                .bitmapTransform(new CropCircleTransformation(context))
                .placeholder(R.drawable.logo)
                .into( imageview);

        if (item.getOnlineStatus()==2) {
            holder.online.setVisibility(View.VISIBLE);
        } else {
            holder.online.setVisibility(View.INVISIBLE);
        }

        holder.name.setText(item.getCreditorName());
        holder.sureMoney.setText("确认金额：" + CommonUtils.resetMoney(item.getConfirmedMoney()) + "元");
        holder.voteMoney.setText("表决金额：" + CommonUtils.resetMoney(item.getVoteMoney()) + "元");
        if(TextUtils.isEmpty(item.getMeetingNumber()) || "0".equalsIgnoreCase(item.getMeetingNumber())) {
            holder.voteCode.setVisibility(View.GONE);
        }else {
            holder.voteCode.setVisibility(View.VISIBLE);
            holder.voteCode.setText("参会编号：" + item.getMeetingNumber());
        }
        if(pageType == 1) {
            holder.voteOpinion.setVisibility(View.VISIBLE);
            holder.voteOpinion.setText(item.getVoteOpinion() == 0 ? "不同意" : "同意");
            holder.modify.setVisibility(View.VISIBLE);
            if(TextUtils.isEmpty(item.getSupplementOpinion())) {
                holder.voteAdvice.setText("补充意见：无");
            }else {
                holder.voteAdvice.setText("补充意见：" + item.getSupplementOpinion());
            }
            holder.voteAdvice.setVisibility(View.VISIBLE);
            holder.operateLayout.setVisibility(View.GONE);
            //holder.cancel.setVisibility(View.GONE);
            //holder.attend.setVisibility(View.GONE);
        }else if(pageType == 2) {
            holder.voteOpinion.setVisibility(View.VISIBLE);
            holder.voteOpinion.setText(item.getVoteOpinion() == 0 ? "不同意" : "同意");
            holder.modify.setVisibility(View.GONE);
            if(TextUtils.isEmpty(item.getSupplementOpinion())) {
                holder.voteAdvice.setText("补充意见：无");
            }else {
                holder.voteAdvice.setText("补充意见：" + item.getSupplementOpinion());
            }
            holder.operateLayout.setVisibility(View.GONE);
            //holder.cancel.setVisibility(View.VISIBLE);
            //holder.attend.setVisibility(View.VISIBLE);
            //holder.cancel.setText("退出参会");
            //holder.attend.setText("表决操作");
        }else if(pageType == 3) {
            holder.voteOpinion.setVisibility(View.GONE);
            holder.modify.setVisibility(View.GONE);
            holder.voteAdvice.setVisibility(View.GONE);
            holder.operateLayout.setVisibility(View.GONE);
            //holder.cancel.setVisibility(View.GONE);
            //holder.attend.setVisibility(View.VISIBLE);
            //holder.attend.setText("参会");
        }
        holder.modify.setVisibility(View.GONE);
    }

    @Override
    public int getItemCount() {
        return mData == null ? 0 : mData.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private ImageView avatar;
        private TextView name;
        private TextView sureMoney;
        private TextView voteMoney;
        private TextView voteCode;
        private TextView online;
        private CheckBox modify;
        private TextView voteOpinion;
        private TextView voteAdvice;
        private RelativeLayout operateLayout;
        private Button cancel;
        private Button attend;//表决 or 参与

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            avatar = itemView.findViewById(R.id.voter_avatar);
            name = itemView.findViewById(R.id.voter_name);
            sureMoney = itemView.findViewById(R.id.voter_sure_money);
            voteMoney = itemView.findViewById(R.id.voter_vote_money);
            voteCode = itemView.findViewById(R.id.voter_code);
            modify = itemView.findViewById(R.id.voter_result_modify);
            voteOpinion = itemView.findViewById(R.id.voter_opinion);
            voteAdvice = itemView.findViewById(R.id.voter_advice);
            operateLayout = itemView.findViewById(R.id.voter_operate);
            cancel = itemView.findViewById(R.id.btn_cancel);
            attend = itemView.findViewById(R.id.btn_vote);
            online = itemView.findViewById(R.id.online);
        }
    }
}
